<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>修改学员信息</title>
</head>
<script type="application/javascript" src="js/jquery-3.7.1.js"></script>
<script type="application/javascript">
    $(function () {
        $(".stuBtn").click(function (){
            var form = $(this).closest("form"); // 获取包含按钮的表单
            var id = form.find("input[name='id']").val();
            var name = form.find("input[name='name']").val();
            var gender = form.find("input[name='gender']").val();
            var age = form.find("input[name='age']").val();
            var address = form.find("input[name='address']").val();
            var email = form.find("input[name='email']").val();

            $.ajax({
                url:"/student",
                data:{
                    action:"stuAlter",
                    id: id,
                    name: name,
                    gender: gender,
                    age: age,
                    address: address,
                    email: email
                },
                type:"GET",
                dataType:"json",
                success:function (data){
                    location.href="/student?action=queryStu";
                }
            });
        });
    });
</script>
<body>
<c:forEach var="stu" items="${stuList}" varStatus="s">
    <div>
        <h1>学员信息</h1>
        <form action="">
            <input type="hidden" name="id" value="${stu.sId}">
            <input type="hidden" name="action" value="stuAlter">
            <p>学员姓名<input type="text" name="name" value="${stu.sName}"></p>
            <p>学员性别<input type="text" name="gender" value="${stu.sGender}"></p>
            <p>学员年龄<input type="text" name="age" value="${stu.sAge}"></p>
            <p>家庭住址<input type="text" name="address" value="${stu.sAddress}"></p>
            <p>Email<input type="email" name="email" value="${stu.sEmail}"></p>
            <p><button type="button" class="stuBtn">修改</button></p>
        </form>
    </div>
</c:forEach>
</body>
</html>
